const NP = require('number-precision');

// 商品总金额，商品总数量
const getTotal = (carts) => {
  let total = {
    price: 0,
    num: 0
  }
  carts.forEach((cart) => {
    total.num = NP.plus(total.num, cart.num)
    total.price = NP.plus(total.price, NP.times(cart.num, cart.product.price))
  })

  return total
}

module.exports = getTotal
